package com.hilihili.controller.userTripletController;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.stream.Collectors;

import com.hilihili.domain.entity.*;
import com.hilihili.service.*;
import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;


/**
 * 前端后台用户Controller
 *
 * @author xhc
 * @date 2023-11-14
 */
@RestController
@RequestMapping("/hilihili/users")
public class UserTripletController extends BaseController
{

    @Autowired
    private IUserLikeService userLikeService;
    @Autowired
    private IUserCoinsService iUserCoinsService;
    @Autowired
    private IFavoritesVideoListService favoritesVideoListService;

    /**
     * 获取前端后台用户 三连 信息（一键三连：点赞收藏投币）
     */
    @GetMapping(value = "/triplet/{videoId}")
    public AjaxResult getTripletInfo(@PathVariable("videoId") Long videoId)
    {
        // 获取当前用户id
        Long userId = SecurityUtils.getUserId();
        if (userId == null){
            return AjaxResult.error(401,"未登录，无法获取用户三连表");
        }
        UserTriplet userTriplet = new UserTriplet();
        List<UserLike> userLikes = userLikeService.selectUserLikeListByUserId(userId,videoId);
        List<UserCoins> userCoins = iUserCoinsService.selectUserCoinsListByUserId(userId,videoId);

        // 查询该视频是否被收藏
        List<FavoritesVideoList> favoritesVideoLists = favoritesVideoListService.selectListByUserIdAndVideoId(userId, videoId);

        userTriplet.setUserLikes(userLikes);
        userTriplet.setUserCoinsList(userCoins);
        userTriplet.setFavoritesVideoLists(favoritesVideoLists);

        return success(userTriplet);
    }

//    -------------------------------------------

}
